﻿using FastCtr;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace test
{
    public partial class Form2 : Form
    {

        NjOmroPLC myplc = new NjOmroPLC("myplc");


        public Form2()
        {
            InitializeComponent();
        }


        //private void Form2_Load(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        myplc.Connect();
        //    }
        //    catch (Exception exp)
        //    {
        //        MessageBox.Show("PLC连接失败！" + exp);

        //    }
        //    try
        //    {


        //        myplc.StartReceivingMessage((varname, varvalue) =>
        //        {
        //            //MessageBox.Show(varname + "\r\n" + varvalue);
        //        });
        //    }
        //    catch (Exception exp)
        //    {
        //        MessageBox.Show("PLC监听失败" + exp);
        //    }
        //}



        private void button1_Click_1(object sender, EventArgs e)
        {
            Form form = new Form();
            form.Controls.Add(myplc);
            form.Show();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            try
            {
                myplc.Connect();
            }
            catch (Exception exp)
            {
                MessageBox.Show("PLC连接失败！" + exp);

            }
            try
            {
                myplc.StartReceivingMessage((varname, varvalue) =>
                {
                    MessageBox.Show(varname + "\r\n" + varvalue);
                });
            }
            catch (Exception exp)
            {
                MessageBox.Show("PLC监听失败" + exp);
            }
        }
    }
}
